package com.ruoyi.api.controller.business;

import com.ruoyi.api.controller.common.AbstractApiController;
import com.ruoyi.business.domain.dto.api.koc.SubmitKocTaskDTO;
import com.ruoyi.business.domain.dto.api.koc.UpdateKocTaskDetailDTO;
import com.ruoyi.business.domain.koc.TbKocTask;
import com.ruoyi.business.domain.koc.TbKocTaskType;
import com.ruoyi.business.domain.vo.TbUserKocPointsRankVO;
import com.ruoyi.business.service.koc.ITbKocTaskService;
import com.ruoyi.business.service.koc.ITbKocTaskTypeService;
import com.ruoyi.business.service.koc.ITbUserKocPointsLogService;
import com.ruoyi.business.service.koc.ITbUserKocTaskInfoService;
import com.ruoyi.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 小程序用户管理Controller
 */
@Validated
@Api(value = "小程序koc业务管理", tags = {"小程序koc业务管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/miniapp/business")
public class ApiBusinessController extends AbstractApiController {


    @Resource
    private ITbUserKocTaskInfoService tbUserKocTaskInfoService;

    @Resource
    private ITbKocTaskTypeService kocTaskTypeService;

    @Resource
    private ITbKocTaskService kocTaskService;

    @Resource
    private ITbUserKocPointsLogService tbUserKocPointsLogService;

    /**
     * 获取全部任务类型与任务
     */
    @ApiOperation("小程序获取全部任务类型与任务")
    @GetMapping("/koc-task-type-all")
    public R<List<TbKocTaskType>> getTbKocTaskTypeInfo() {
        return R.ok(kocTaskTypeService.queryAll());
    }


    /**
     * 根据任务id查询任务配置
     */
    @ApiOperation("根据任务id查询任务配置")
    @GetMapping("/koc-task-by-id/{taskId}")
    public R<TbKocTask> getTbKocTaskInfo(@ApiParam("taskId") @NotNull(message = "任务主键不能为空") @PathVariable Long taskId) {
        return R.ok(kocTaskService.getById(taskId));
    }

    /**
     * 提交koc任务
     */
    @ApiOperation("小程序提交koc任务")
    @PostMapping("/submit-koc-task")
    //@RepeatSubmit(interval = 500, timeUnit = TimeUnit.MILLISECONDS, message = "不允许重复提交")
    public R<Boolean> submitKocTask(@Validated @RequestBody SubmitKocTaskDTO dto) {
        return R.ok(tbUserKocTaskInfoService.userSubmitKocTask(getUserId(), dto));
    }

    /**
     * 删除koc任务
     */
    @ApiOperation("小程序删除koc任务")
    @DeleteMapping("/del-koc-task-info/{kocTaskInfoId}")
    public R<Boolean> delKocTaskInfo(
        @ApiParam("用户提交koc任务id") @NotNull(message = "主键不能为空") @PathVariable Long kocTaskInfoId) {
        return R.ok(tbUserKocTaskInfoService.delKocTaskInfo(getUserId(), kocTaskInfoId));
    }

    /**
     * 修改koc任务详情
     */
    @ApiOperation("小程序更新koc任务详情")
    @PostMapping("/update-koc-task-detail")
   // @RepeatSubmit(interval = 500, timeUnit = TimeUnit.MILLISECONDS, message = "不允许重复提交")
    public R<Boolean> modifyKocTaskDetail(@Validated @RequestBody UpdateKocTaskDetailDTO dto) {
        return R.ok(tbUserKocTaskInfoService.modifyKocTaskDetail(getUserId(), dto));
    }


    /**
     * 当前期次用户积分排行榜
     */
    @ApiOperation("当前期次用户积分排行榜")
    @GetMapping("/user-koc-points-rank")
    public R<TbUserKocPointsRankVO> userKocPointsRank() {
        return R.ok(tbUserKocPointsLogService.userPointsRank());
    }


}
